import request from '@/utils/request'
import type { HasSpuResponseData, SkuInfoData, AllTradeMark, SpuHasImg, HasSaleAttrResponseData, SpuData } from "./types"
enum API {
    // 获取已有spu
    HASSUP_URL = "/admin/product/",
    // 获取全部品牌
    ALLTRADEMARK_URL = "/admin/product/baseTrademark/getTrademarkList",
    // 获取某个spu的照片墙数据
    IMAGE_URL = "/admin/product/spuImageList/",
    // 某个spu销售属性列表
    SPUHASSALEATTR_URL = "/admin/product/spuSaleAttrList/",
    // 获取整个系统所有的spu属性
    ALLSALEATTR_URL = "/admin/product/baseSaleAttrList",
    // 追加一个新的spu
    ADDSPU_URL = "/admin/product/saveSpuInfo",
    // 修改已有的spu
    UPDATESPU_URL = "/admin/product/updateSpuInfo",
    // 查看某一个spu下的所有sku
    SKUINFO_URL = "/admin/product/findBySpuId/",
    // 删除某一个spu
    DELETESPU_URL = "/admin/product/deleteSpu/"
}

export const reqHasSpu = (page: number, limit: number, category3Id: number | string) => request.get<any, HasSpuResponseData>(API.HASSUP_URL + `${page}/${limit}?category3Id=${category3Id}`)
// 获取全部spu品牌的接口
export const reqAllTrademark = () => request.get<any, AllTradeMark>(API.ALLTRADEMARK_URL)
// 获取某个spu照片墙数据
export const reqSpuImageList = (spuId: number) => request.get<any, SpuHasImg>(API.IMAGE_URL + spuId)
// 获取某个spu销售属性列表
export const reqSpuHasSaleAttr = (spuId: number) => request.get<any, any>(API.SPUHASSALEATTR_URL + spuId)
// 全部的销售属性
export const reqAllSaleAttr = () => request.get<any, HasSaleAttrResponseData>(API.ALLSALEATTR_URL)
// 添加或者修改spu
export const addOrUpdateSpu = (data: SpuData) => {
    if (data.id) {
        return request.post<any, any>(API.UPDATESPU_URL, data)
    } else {
        return request.post<any, any>(API.ADDSPU_URL, data)
    }
}
// 查看某一个spu下的所有sku
export const reqSkuList = (spuId: number | string) => request.get<any, SkuInfoData>(API.SKUINFO_URL + spuId)
// 删除某一个spu
export const reqDelSpu = (spuId: number | string) => request.delete<any, any>(API.DELETESPU_URL + spuId)